package org.flint92.springboot.mbean.jmx.bean;

import org.springframework.jmx.export.annotation.ManagedAttribute;
import org.springframework.jmx.export.annotation.ManagedOperation;
import org.springframework.jmx.export.annotation.ManagedResource;
import org.springframework.stereotype.Component;

import java.util.StringJoiner;

/**
 * @author flint92
 */
@ManagedResource(
        objectName = "org.flint92.springboot.mbean.jmx.bean.SimpleBean:type=SimpleBean",
        description = "This is a simple bean which is hosted by Spring."
)
@Component
public class SimpleBean {

    private Long id;

    private String name;

    private Integer value;

    @ManagedAttribute(description = "Id Attribute")
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @ManagedAttribute(description = "Name Attribute")
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @ManagedAttribute(description = "Value Attribute")
    public Integer getValue() {
        return value;
    }

    public void setValue(Integer value) {
        this.value = value;
    }

    @ManagedOperation(description = "Method named display")
    public String display() {
        return this.toString();
    }

    @Override
    public String toString() {
        return new StringJoiner(", ", SimpleBean.class.getSimpleName() + "[", "]")
                .add("id=" + id)
                .add("name='" + name + "'")
                .add("value=" + value)
                .toString();
    }
}
